import api from '../../api/index'
Page({
  data: {
    userInfo: {
      phone: '188888888',
      name: '',
    },
    classIndex: '',
    yearIndex: '',
    classList: [
      { id: 1, name: '一班' },
      { id: 1, name: '二班' },
      { id: 1, name: '3班' },
      { id: 1, name: '4班' },
    ],
    yearList: [
      { id: 1, name: '95' },
      { id: 1, name: '96' },
      { id: 1, name: '97' },
      { id: 1, name: '98' },
    ],
  },
  onLoad(options) {

  },
  onReady() {

  },
  onShow() {

  },
  bindPickerChange(e) {
    const { value } = e.detail
    const { name } = e.currentTarget.dataset
    console.log(e);
    this.setData({ [name]: value })
  },
  changeName(e) {
    const { value } = e.detail
    let userInfo = this.data.userInfo
    let name = e.currentTarget.dataset
    userInfo[name] = value
    this.setData({ userInfo })
  },
  submit() {
    const { userInfo, classIndex, yearIndex, yearList, classList } = this.data
    if (!userInfo.name) {
      return wx.showToast({ icon: 'none', title: '请输入昵称', })
    }
    if (yearIndex === '') {
      return wx.showToast({ icon: 'none', title: '请选择年份', })
    }
    if (classIndex === '') {
      return wx.showToast({ icon: 'none', title: '请选择年级', })
    }
    const data = { ...userInfo, year: yearList[yearIndex].id, class: classList[classIndex] }
    api.base.listByParentId()
  },
  wxLogin(e) {
    console.log(111);
    console.log(e);
    wx.login({
      success(res) {
        if (res.code) {
          console.log(res);
          //发起网络请求
          wx.request({
            url: 'https://example.com/onLogin',
            data: {
              code: res.code
            }
          })
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    })
  }
})